package com.jhmk.jhecis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.jhmk.jhecis.domain.common.R;
import com.jhmk.jhecis.domain.InterfaceTool;
import com.jhmk.jhecis.mapper.InterfaceToolMapper;
import com.jhmk.jhecis.service.InterfaceToolService;
import com.jhmk.jhecis.utils.RandomGUID;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;


@Service
public class InterfaceToolServiceImpl extends ServiceImpl<InterfaceToolMapper, InterfaceTool> implements InterfaceToolService {


    @Resource
    private SqlSessionTemplate sqlSessionTemplate;

    public void executeSql(String replaceSql) {
        if (StringUtils.isEmpty(replaceSql)) {
            return;
        }
        try {
            SqlSession sqlSession = sqlSessionTemplate.getSqlSessionFactory().openSession();
            sqlSession.getConnection().prepareStatement(replaceSql).execute(replaceSql);
            sqlSession.commit();
            sqlSession.close();
        } catch (SQLException e) {

        }
    }


    public String sqlRun() {
        String sql = new SQL()
                .SELECT("*")
                .FROM("InterfaceTool")
                .WHERE("id = #{id}", "name = #{name}")
                .toString();
       // Connection connection = DriverManager.getConnection("数据库连接");
        SqlRunner sqlRunner = new SqlRunner();
        Map<String, Object> result = sqlRunner.selectOne(sql, 1, "Jason");
         return "222";
    }
    @Override
    public  InterfaceTool selectJavascriptcodeAndFunctionnameByInterfacecode(String interfacecode){

       return baseMapper.selectJavascriptcodeAndFunctionnameByInterfacecode(interfacecode);
    }
}
